package com.example.demo.model;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.CreationTimestamp;
import org.hibernate.annotations.Type;
import org.joda.money.Money;

import javax.persistence.*;
import javax.validation.constraints.NotNull;
import java.time.LocalDate;
import java.util.List;

@Entity//连接数据库表
@Table(name = "t_order")
@Data
@NoArgsConstructor//构造函数
@AllArgsConstructor
@Builder//可以采用链式写法
public class Order {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer id;

    @Column(updatable = false)
    @CreationTimestamp
    private LocalDate createTime;

    @ManyToMany
    @JoinTable(name="t_order_drink", joinColumns = {@JoinColumn(name = "drink_order_id")})
    //@OrderBy("createTime") //排序操作
    private List<Drink> items;

    private String customer;

    private Integer state;

    @Column
    @Type(type = "org.jadira.usertype.moneyandcurrency.joda.PersistentMoneyAmount",
            parameters = {@org.hibernate.annotations.Parameter(name = "currencyCode", value = "CNY")})
    @NotNull
    private Money price;
}
